
import React from 'react'
import ReactDOM from 'react-dom'
import * as WechatLinkAction  from '../../actions/WechatLinkAction';
import { connect }  from 'react-redux';

import WechatLinkList from './WechatLinkList'
import WechatLinkEdit from './WechatLinkEdit'

class WechatLinkBody extends React.Component {

  constructor(props) {
    super(props);

    this.state = {
      activeData: {},
    }
  }

  componentDidMount() {
    var self = this;
    this.$wechatLinkEdit = $(ReactDOM.findDOMNode(this.refs.WechatLinkEdit))

    this.props.dispatch(
      WechatLinkAction.loadWechatLinkAsync({})
    )
  }

  componentDidUpdate() {
    // console.log(this.props.workOrder)
  }

  onDetailClick(data) {
    this.setState({
      activeData: data
    })
    this.$wechatLinkEdit.modal("show")
  }

  onDataSubmit(data) {
    this.props.dispatch(
      WechatLinkAction.updateWechatLinkAsync(data)
    )
    this.$wechatLinkEdit.modal("hide")
  }

  render() {
    var self = this;

    return (
      <div className="content-body work-content-body" >
        <WechatLinkList
          data = {this.props.data}
          onDetailClick = {this.onDetailClick.bind(this)}
        />
        <WechatLinkEdit
          ref = "WechatLinkEdit"
          data = {this.state.activeData}
          onDataSubmit = {this.onDataSubmit.bind(this)}
        />
      </div>
    )
  }
}

const mapStateToProps = (state, ownProps) => {
  return {
          data: state.wechatLink.data,
         }
}

export default connect(mapStateToProps)(WechatLinkBody);
